﻿#region Header

/*
Remote views based on linq
By

Pascal Hauser 
Dipl. Ing. in Informatik, Hochschule für Technik Rapperswil, 2006
Master Thesis, Hochschule für Technik Rapperswil, 2008-2010

and

Raphael Gfeller
Dipl. Ing. in Informatik, Hochschule für Technik Rapperswil, 2006
Master Thesis, Hochschule für Technik Rapperswil, 2008-2010

*/

#endregion

#region Usings

using System;
using Sebarf.Services.Interfaces;
using Sebastof.Services.Interfaces;
using Utils;

#endregion

namespace Sebastof.Services.Impl {
	/// <summary>
	/// Impl of the <see cref="IObjectIdentifierLocatorService"/>
	/// </summary>
	public class ObjectIdentifierLocatorService : Service, IObjectIdentifierLocatorService {
		#region Public Properties

		/// <summary>
		/// Reference to the meta-data locator service
		/// </summary>
		[ServiceRequest]
		public IMetadataLocatorService MetadataLocatorService { get; set; }

		#endregion

		#region IObjectIdentifierLocatorService Members

		/// <summary>
		/// Returns the if of an object. 
		/// If the object provides an id, the id the object provides is returned,
		/// else the id generated by the framework is returned.
		/// </summary>
		/// <param name="value"></param>
		/// <returns></returns>
		public string GetIdentityForObject(object value) {
			// object provides its unique id
			if (value is IIdentifiable) {
				return (value as IIdentifiable).Id;
			}

			// use the metadata locator server for standard object
			return MetadataLocatorService.GetMetadata(value, "UniqueIdentifier", Guid.NewGuid().ToString());
		}

		#endregion
	}
}